# 1.0mm 冷轧板卷
import time
import parsel
import common.dataBase as db
import requests


def get_data(url):
    response = requests.get(url)
    selectors = parsel.Selector(response.text)
    # #table > tbody > tr:nth-child(5) > td:nth-child(11) > a
    price = selectors.css('#t8 table:nth-child(1) tr:nth-child(7) td:nth-child(11)::text').get().strip()
    return price


def app():
    url = 'http://baojia.steelcn.cn/'
    d = get_data(url)
    print(d)
    name = '1.0mm 冷轧板卷'
    price = d
    price_range = ''
    today = time.strftime('%Y-%m-%d', time.localtime())
    insert_sql = f'INSERT INTO mat_price VALUES (null, "{name}", "{price}","{price_range}", "{today}", "{url}")'
    db.save([insert_sql])


if __name__ == "__main__":
    app()
